﻿using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEngine;
[Serializable]
public class GameData
{
	public float contentWidth = 800;
	public float contentHeight = 800;
	public int hCount = 20; //横数
	public int vCount = 20; //竖数
	public bool isShowFenGeXian;//是否显示中间的分割线
	public bool isShowToolText;//道具是否显示文本
	public int setX = 4;
	public int setY = 4;
	public int setZ = 4;
	public GameData()
	{
		Rest();
	}
	public void Rest()
	{
		contentWidth = 800;
		contentHeight = 800;
		hCount = 20;
		vCount = 20;
		isShowFenGeXian = false;
		isShowToolText = false;
		setX = 4;
		setY = 4;
		setZ = 4;
	}
}

public class LocalData
{
	public GameData gameData = null;//配置数据
	private string ID = "LocalData";
	public LocalData()
	{
		Init();
	}
	public void Init()
	{
		if (PlayerPrefs.HasKey(ID)) {
			gameData = JsonConvert.DeserializeObject<GameData>(PlayerPrefs.GetString(ID));
		} else {
			gameData = new GameData();
		}
	}
	public void SaveData()
	{
		string data = JsonConvert.SerializeObject(gameData);
		PlayerPrefs.SetString(ID, data);
	}
	/// <summary>
	/// 打印json
	/// </summary>
	/// <typeparam name="T"></typeparam>
	/// <param name="data"></param>
	public static void DebugLogJson<T>(T data)
	{
		Debug.LogError(JsonConvert.SerializeObject(data));
	}

}